from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():

    # 1. 声明一个 'port' 参数, 这样您可以在命令行中指定
    port_arg = DeclareLaunchArgument(
        'port',
        default_value='/dev/ttyACM0',
        description='TTY port for the Leader Arm hardware interface'
    )

    # 2. 启动 Leader 臂的硬件接口节点 (来自 so101_hw_interface)
    leader_hw_node = Node(
        package='so101_hw_interface',
        executable='so101_leader_pub',
        name='so101_leader_publisher',
        output='screen',
        parameters=[{
            'port': LaunchConfiguration('port')
        }]
    )

    # 3. 启动 Leader-Follower 桥接节点
    leader_bridge_node = Node(
        package='joystick_alphadog_with_so101_servo',
        executable='so101_leader_follower_bridge',
        name='so101_leader_follower_bridge',
        output='screen'
    )

    return LaunchDescription([
        port_arg,
        leader_hw_node,
        leader_bridge_node,
    ])